package com.cares.infobird.service;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cares.core.base.controller.BaseController;
import com.cares.core.base.service.BaseService;
import com.cares.core.utils.StringUtil;

/**
 * 团队参数处理业务类
 * 
 */
@Service("messageSendService")
@Transactional(readOnly = true)
public class MessageSendService extends BaseService {

	private static Logger logger = LoggerFactory.getLogger(MessageSendService.class);
	
	public Map<String, String> sendSIMMsg(String mobile, String msg) {

		Map<String, String> map = new HashMap<String, String>();
		try {
			logger.debug("# sendSIMMsg : " + mobile + ">>" + msg);
			if (StringUtil.isValidMobileNo(mobile)) {
				//FIXME 短信发送
				map.put(BaseController.AJAX_MESSAGE, "Y");
			} else {
				map.put(BaseController.ERR_MESSAGE, "Mobile No InValid ");
				map.put(BaseController.AJAX_MESSAGE, "N");
			}
		} catch (Exception ex) {
			logger.error(ex.getMessage());
			map.put(BaseController.ERR_MESSAGE, ex.getMessage());
			map.put(BaseController.AJAX_MESSAGE, "N");
		}
		return map;
	}

	public void sendSysMsg(String msg) {
		try {
			if(StringUtil.isEmpty(msg))
				return;
			
			if(msg.length()>60){
				msg = msg.substring(0, 60);
			}
			String[] tel = new String[]{"18930823570"};
			for (String mobile : tel) {
				this.sendSIMMsg(mobile,"Bootstrap Exception："+ msg);
			}
		} catch (Exception ex) {
			logger.error(ex.getMessage());
		}
	}
}
